using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ECommerce.Library.DataStructure;
using AutoGear.BLL;
using System.Collections.Generic;
using ECommerce.Library.Web;
using ECommerce.Library;
using System.Text;
using ECommerce.Library.ECommerce;

public partial class controls_wucFeaturedList : BaseControl
{
    protected StringBuilder MyData = new StringBuilder();
    private int _maxItem = 9;

    public int MaxItem
    {
        get { return _maxItem; }
        set { _maxItem = value; }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                LoadRepeaterItems();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected void LoadRepeaterItems()
    {
        ReadWriteCustomCollection<Product> featuredProduct = Product.FeaturedProducts(MaxItem);
        rptHorizontal.DataSource = featuredProduct;
        rptHorizontal.DataBind();
    }

    protected void Horizontal_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Product product = (Product)e.Item.DataItem;
                string[] words = product.ProductUrl.Split('/');
                string lasturl = string.Empty;
                foreach (string word in words)
                {
                    if (word.Contains(".aspx"))
                    {
                        lasturl = word.ToString();
                    }
                }
                // product image
                Image imgProduct = (Image)e.Item.FindControl("imgProduct");
                System.Drawing.Size originalImageDimension = ImageResizer.GetImageDimension(product.ProductImageSmallThumbnail);
                if (originalImageDimension.Width > 150)
                {
                    imgProduct.Style.Add("width", "150px;");
                }

                imgProduct.ImageUrl = ImageResizer.CheckImageMissing(product.ProductImageSmallThumbnail, AutoGear.BLL.SiteSettings.NoImageSmallThumbnailUrl);
                string imgUrl = imgProduct.ImageUrl.Replace(SiteSettings.SiteBaseUrl, "~");
                System.Drawing.Size imageSize = ImageResizer.GetImageDimension(imgUrl);
                if (imageSize.Height > 120)
                {
                    Unit imageHeight = new Unit(120);
                    imgProduct.Height = imageHeight;
                }
                
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

}
